Page({

  /**
   * 页面的初始数据
   */
  data: {
    sale:[
      {url:'../../images/swiper_1.png'},
      {url:'../../images/swiper_2.png'},
      {url:'../../images/swiper_3.png'}
    ],
    icon: [
      [{ text: '笔记本', icon: '../../images/icon_1.png',id:'01'},
       { text: '台式机', icon: '../../images/icon_2.png',id:'02'},
       { text: '电脑外设', icon: '../../images/icon_3.png',id:'03' },
       { text: '手机配件', icon: '../../images/icon_4.png',id:'04'}
    ],
      [{ text: '智能手机', icon: '../../images/icon_5.png',id:'05'},
       { text: 'pc配件', icon: '../../images/icon_6.png',id:'06'},
       { text: '数码相机', icon: '../../images/icon_7.png',id:'07'},
       { text: '智能穿戴', icon: '../../images/icon_8.png',id:'08'}
      ]]
  },

  toProductList:function(e){
    //console.log(e);
    //console.log(e.currentTarget.dataset.id);
    //console.log(e.currentTarget.dataset.name)
    var listId = e.currentTarget.dataset.id;
    var listName = e.currentTarget.dataset.name;

    wx.navigateTo({
      url: '/pages/productList/productList?listId='+listId+'&listName='+listName,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    var list = wx.getStorageSync("list");
    if (list) { 
      that.setData({
        list: list
      })
    }

    wx.request({
      url:'https://xuzhichao.cn/dianshang_typelist',
      success:function(res){
        //console.log(res)
        list = res.data.dianshang_typelist
        //console.log(list)
          that.setData({
            list: list
          })
        //console.log(list)
          wx.setStorageSync("list",list)
          //console.log(list)
      }
      
    })
    console.log('首页获取缓存成功\n',list);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})